<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>添加/编辑角色</title>
<script type="text/javascript" src="${base}/template/common/js/jquery.tools.js"></script>
<script type="text/javascript" src="${base}/template/common/js/jquery.validate.js"></script>
<script type="text/javascript" src="${base}/template/common/js/jquery.validate.methods.js"></script>
<script type="text/javascript">
$().ready(function() {

	var $validateErrorContainer = $("#validateErrorContainer");
	var $validateErrorLabelContainer = $("#validateErrorContainer ul");
	var $validateForm = $("#validateForm");
	
	var $allChecked = $("#validateForm .allChecked");
	
	$allChecked.click( function() {
		var $this = $(this);
		var $thisCheckbox = $this.parent().parent().find(":checkbox");
		if ($thisCheckbox.filter(":checked").size() > 0) {
			$thisCheckbox.attr("checked", false);
		} else {
			$thisCheckbox.attr("checked", true);
		}
		return false;
	});
	
	// 表单验证
	$validateForm.validate({
		errorContainer: $validateErrorContainer,
		errorLabelContainer: $validateErrorLabelContainer,
		wrapper: "li",
		errorClass: "validateError",
		ignoreTitle: true,
		rules: {
			"role.name": "required"
		},
		messages: {
			"role.name": "请填写角色名称"
		},
		submitHandler: function(form) {
			$(form).find(":submit").attr("disabled", true);
			form.submit();
		}
	});
	
	$.validator.addMethod("roleAuthorityListRequired", $.validator.methods.required, "请选择管理权限");
	
	$.validator.addClassRules("roleAuthorityList", {
		roleAuthorityListRequired: true
	});
	
})
</script>
</head>
<body class="input role">
	<div class="bar">
		添加/编辑角色
	</div>
	<div id="validateErrorContainer" class="validateErrorContainer">
		<div class="validateErrorTitle">以下信息填写有误,请重新填写</div>
		<ul></ul>
	</div>
	<div class="body">
	<@form.form id="validateForm" modelAttribute="role" action="${base}/admin/role/save/${(role.id)!}" method="post">
		<input type="hidden" name="id" value="${(role.id)!}"/>
		
		<table class="inputTable">
		<tr>
			<th>角色名称: </th>
			<td>
				<input type="text" name="name" class="formText" value="${(role.name)!}" />
				<label class="requireField">*</label>
			</td>
		</tr>
		<tr>
			<th>
				描述: ${perList}
			</th>
			<td>
				<textarea name="description" class="formTextarea">${(role.description)!}</textarea>
			</td>
		</tr>
		<tr>
			<td colspan="2">
				&nbsp;
			</td>
		</tr>
		<tr class="authorityList">
			<th>
				<a href="#" class="allChecked" title="点击全选此类权限">商品管理: </a>
			</th>
			<td>
				<@checked permission="account:manager" permissionName="账号管理" filter="*"/> 
				<@checked permission="admin:list"      permissionName="人员管理" filter="/account/admin!list.action"/> 
				<@checked permission="admin:input"     permissionName="人员查看" filter="/account/admin!input.action"/> 
				<@checked permission="admin:save"      permissionName="人员编辑" filter="/account/admin!save.action"/> 
				<@checked permission="admin:multiDel"  permissionName="人员删除" filter="/account/admin!multiDel.action"/> 
				<@checked permission="role:list"       permissionName="角色管理" filter="/admin/account/role!list"/> 
				<@checked permission="role:input"      permissionName="角色查看" filter="/account/role!input.action"/> 
				<@checked permission="role:save"       permissionName="角色编辑" filter="/account/role!save.action"/> 
			</td>
		</tr>
		<#if (role.isSystem)!false>
			<tr>
				<th>
					&nbsp;
				</th>
				<td>
					<span class="warnInfo"><span class="icon">&nbsp;</span>系统提示: </b>系统内置角色不允许修改!</span>
				</td>
			</tr>
		</#if>
		</table>
		<div class="buttonArea">
				<input type="submit" class="formButton" value="确  定" hidefocus />&nbsp;&nbsp;
				<input type="button" class="formButton" onclick="window.history.back(); return false;" value="返  回" hidefocus />
		</div>
	</@form.form>
	</div>
</body>
</html>




<#macro checked permission permissionName filter>
<#compress>
<label title="${filter}">
<input type="checkbox" name="permissionList" class="roleAuthorityList" value="${permission}" <#rt>
<#if role??>
<#if role.name?exists && role.name?trim == "管理员">
		checked = "checked" 	
<#else>	
    <#--
	<#if role.permissionList?index_of(permission) gt 0>
		checked = "checked"
	</#if>
	-->
</#if> 
<#else>
<#if name?exists && name?trim == "管理员">
	checked = "checked" 	
<#else>
	<#--
	<#if permissionList?index_of(permission) gt 0>
		checked = "checked"
	</#if>
	 -->
</#if> 
</#if>
>${permissionName}
</label>	
</#compress>	
</#macro>